<template>
    <el-table :data="arrangeLogs" border highlight-current-row header-cell-class-name="table-header">
        <el-table-column prop="id" label="ID" width="60" />
        <el-table-column label="类型">
            <template slot-scope="scope">
                <span v-if="scope.row.type == 'date'">指定日期</span>
                <span v-if="scope.row.type == 'week'">每周</span>
                <span v-if="scope.row.type == 'day'">每天</span>
            </template>
        </el-table-column>
        <el-table-column prop="class.name" label="班级名称" />
        <el-table-column prop="course.name" label="课程名称" />
        <el-table-column prop="teacher.name" label="教师名称" />
        <el-table-column prop="room.name" label="教室名称" />
        <el-table-column prop="course_num" label="课时" />
        <el-table-column prop="start_date" label="开始日期" />
        <el-table-column prop="end_date" label="结束日期" />
        <el-table-column prop="time" label="时间" />
        <el-table-column prop="weeks" label="星期" width="80" />
        <el-table-column label="操作" width="120">
            <template slot-scope="scope">
                <el-button type="text" @click="revokeArrange(scope.row.id)">撤销排课</el-button>
            </template>
        </el-table-column>
    </el-table>
</template>
<script>
    import courseArrangeApi from '@/api/course-arrange'
    export default {
        name: 'ArrangeLogs',
        data() {
            return {
                arrangeLogs: []
            }
        },
        created() {
            this.getLogs()
        },
        methods: {
            getLogs() {
                courseArrangeApi.logs().then(res => { this.arrangeLogs = res.data })
            },
            // 撤销排课
            revokeArrange(id) {
                this.$confirm('确定撤销该次排课吗？', '提示').then(() => {
                    courseArrangeApi.revoke(id).then(res => {
                        this.getLogs()
                        this.search()
                    })
                }).catch(() => {})
            }
        }
    }
</script>
